﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.ServiceHosting.StorageClient;
using System.IO;

namespace BusinessLogic.Blob
{
    public class BingBlob
    {

        private static BlobStorage storage;
        private static BlobContainer bingContainer;

        static BingBlob()
        {
            storage = BlobStorage.Create(StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration());
            bingContainer = storage.GetBlobContainer("bingtemp");
        }

        public static BlobContainer ThumbContainer
        {
            get
            {
                if (!bingContainer.DoesContainerExist())
                {
                    bingContainer.CreateContainer(null, ContainerAccessControl.Public);
                }
                return bingContainer;
            }
        }

        public static bool Store(string blobName, string contentType, Stream stream, bool shouldOverride)
        {
            BlobProperties properties = new BlobProperties(blobName)
            {
                ContentType = contentType
            };

            BlobContents contents = new BlobContents(stream);

            return ThumbContainer.CreateBlob(properties, contents, shouldOverride);
        }

        public static BlobProperties GetBlob(string blobName, Stream inputStream)
        {
            BlobContents contents = new BlobContents(inputStream);
            return ThumbContainer.GetBlob(blobName, contents, false);
        }
            
    }
}
